package com.pcbly.web.persistence;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;

import com.pcbly.web.components.hibernate.support.Page;

public interface BaseDao<T> extends Serializable {
	void clear() throws Exception;

	Criteria getEntityCriteria() throws Exception;

	@SuppressWarnings("hiding")
	<T> Criteria createCriteria(Class<T> entityClass, Criterion... criterions)
			throws Exception;

	@SuppressWarnings("hiding")
	<T> Criteria createCriteria(Class<T> entityClass, String orderBy,
			boolean isAsc, Criterion... criterions) throws Exception;

	Criteria createCriteria(Criterion... criterions) throws Exception;

	void batchHQL(String hql, Object[] values) throws Exception;

	Criteria createCriteria(String orderBy, boolean isAsc,
			Criterion... criterions) throws Exception;

	Query createQuery(String hql, Object... values) throws Exception;

	void evit(Object entity) throws Exception;

	List<T> find(String hql, Object... values) throws Exception;

	@SuppressWarnings("hiding")
	<T> List<T> findBy(Class<T> entityClass, String propertyName, Object value)
			throws Exception;

	@SuppressWarnings("hiding")
	<T> List<T> findBy(Class<T> entityClass, String propertyName, Object value,
			String orderBy, boolean isAsc) throws Exception;

	List<T> findBy(String propertyName, Object value) throws Exception;

	List<T> findBy(String propertyName, Object value, String orderBy,
			boolean isAsc) throws Exception;

	@SuppressWarnings("hiding")
	<T> T findUniqueBy(Class<T> entityClass, String propertyName, Object value)
			throws Exception;

	T findUniqueBy(String propertyName, Object value) throws Exception;

	void flush() throws Exception;

	@SuppressWarnings("hiding")
	<T> T get(Class<T> entityClass, Serializable id) throws Exception;

	T get(Serializable id) throws Exception;

	List<T> getAll() throws Exception;

	List<T> getAll(Class<T> entityClass) throws Exception;

	List<T> getAll(Class<T> entityClass, String orderBy, boolean isAsc)
			throws Exception;

	List<T> getAll(String orderBy, boolean isAsc) throws Exception;

	Serializable getId(Class<T> entityClass, Object entity) throws Exception;

	/**
	 * 获取Entity对象的主键名.
	 */
	String getIdName(Class<T> clazz) throws Exception;

	boolean isUnique(Class<T> entityClass, Object entity,
			String uniquePropertyNames) throws Exception;

	boolean isUnique(Object entity, String uniquePropertyNames)
			throws Exception;

	Page<T> pagedQuery(Class<T> entityClass, int pageNo, int pageSize,
			Criterion... criterions) throws Exception;

	Page<T> pagedQuery(Class<T> entityClass, int pageNo, int pageSize,
			String orderBy, boolean isAsc, Criterion... criterions)
			throws Exception;

	Page<T> pagedQuery(Criteria criteria, int pageNo, int pageSize)
			throws Exception;

	Page<T> pagedQuery(String hql, int pageNo, int pageSize, Object... values)
			throws Exception;

	void remove(Object o) throws Exception;

	void removeById(Class<T> entityClass, Serializable id) throws Exception;

	void removeById(Serializable id) throws Exception;

	void saveObject(Object o) throws Exception;

	List<HashMap<String, String>> findCommnonDataBeanExt(String tableName,
			String id) throws Exception;

	void saveCommnonDataBeanExt(String sql) throws Exception;

	boolean getHasCommnonDataBeanExt(String tableName, String id)
			throws Exception;

}
